<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>麦知网——学问有余，可为人师</title>

<!-- Bootstrap core CSS -->
<link href="../css/bootstrap.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="../css/non-responsive.css" rel="stylesheet">
<link href="../css/font-awesome.min.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../../docs-assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.min.js"></script>
      <script src="http://cdn.bootcss.com/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
<link href="../css/message.css" rel="stylesheet">    
 
</head>
<body>
	{% include 'public/common/header.html' %}
<div class="container" style="margin-top:45px">
		<div class="row">
			<div class="col-xs-12">
				<div class="mes_title">
					<div class="pull-left mes_title1"><b>您收到的私信</b></div>
					<div class="pull-right"><button type="button" class="btn btn-warning btn-sm" onclick="ignore_message();">忽略全部</button></div>
					<div class="pull-right"><button type="button" class="btn btn-primary btn-sm" onclick="del_message();">删除全部</button></div>
					<div class="clearfix"></div>
				</div>
				<div>
					<table class="table table-hover">
						<tbody>
<!--  一条私信循环开始处 -->{% for m in messages %}
							<tr id="the_mes{{m.5}}" onMouseOver="show_del({{m.5}});" onMouseOut="hide_del({{m.5}});">
								<td style="padding:10px 20px 10px 20px;">
									<div>
										<div class="pull-left"><a href="{% url 'users:home' m.0 %}">{{m.1}}</a>对您说</div>
										<div class="pull-left mes_content">
											<a href="javascript:void(0)" onclick="mes_read({{m.0}});">{{m.2}}</a>
										</div>
										<div class="pull-right time">{{m.3|date:"Y-m-d H:i:s"}}</div>
										<div id="del{{m.5}}" class="pull-right pull_right del">
											<a href="javascript:void(0)" type="button" class="btn btn-info btn-xs" onclick="del_a_mes({{m.5}});">删除</a>
										</div>
<!-- 如果未读 开始处 -->{% ifequal m.4 1 %}
										<div class="pull-right pull_right"><span class="label label-warning">未读</span></div>
<!-- 如果未读 结束处 -->{% endifequal %}
										<div class="clearfix"></div>
									</div>
								</td>
							</tr>
<!--  一条私信循环结束处 -->{% endfor %}
						</tbody>
					</table>

					<ul class="pager">
					{% if messages.has_previous %}
					  <li><a href="?page={{ message.previous_page_number }}">&larr;上一页</a></li>
					{% endif %}
					第 {{ messages.number }} 页   共{{ messages.paginator.num_pages }} 页.
					{% if messages.has_next %}
					  <li><a href="?page={{ message.next_page_number }}">下一页&rarr;</a></li>
					{% endif %}
					</ul>
				</div>
			</div>
		</div>
</div>
	
	
	
	
	<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
	<script src="../js/jquery.min.js"></script>
	
	<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
	<script src="../js/bootstrap.js"></script>
	<script>
		var xmlHttp; 

	function createXMLRequest(){
		if(window.ActiveXObject){
			xmlHttp=new ActiveXObject("Microsoft.XMLHttp");
		} else if(window.XMLHttpRequest){
			xmlHttp=new XMLHttpRequest();
		}
	}
//显示所有收到的私信
		function mes_read(from_id){
		createXMLRequest(); 
		var url="/users/mes_read/?from_id="+from_id;
		xmlHttp.open("GET",url);
		xmlHttp.onreadystatechange=function(e){
			if(xmlHttp.readyState==4 && xmlHttp.status==200){
					re=xmlHttp.responseText;//alert(re);
					if(re){
						$("#havent").html($("#havent").html()-1);
						window.location.href='/users/mestalk/'+from_id;
			    		
					}else{
						e.preventDefault();
			    		$.scojs_message('服务器出错啦～ ：）', $.scojs_message.TYPE_ERROR);
					} 
				} /*else {
					e.preventDefault();
			    	$.scojs_message('服务器有小怪兽在捣乱～我们正在尽力捕捉～ ：）', $.scojs_message.TYPE_ERROR);
				}*/
			};
			xmlHttp.send(); 
	}


//删除所有私信
		function del_message(){
			if (confirm("您确认要删除所有信息吗？")){
			    createXMLRequest();                       
				
				var url="/users/del_message/";
				xmlHttp.open("GET",url);
				xmlHttp.onreadystatechange=function(){
					if(xmlHttp.readyState==4 && xmlHttp.status==200){
						location.reload();
					}		
				};
				xmlHttp.send(); 
			}
		}
		function ignore_message(){
			if (confirm("您确认要忽略所有信息吗？")){
			    createXMLRequest();                       
				
				var url="/users/ignore_message/";
				xmlHttp.open("GET",url);
				xmlHttp.onreadystatechange=function(){
					if(xmlHttp.readyState==4 && xmlHttp.status==200){
						location.reload();
					}		
				};
				xmlHttp.send(); 
			}
		}
//删除一条私信
		function del_a_mes(mes_id){
		    createXMLRequest();      
			var url="/users/delames/?mes_id="+mes_id;
			xmlHttp.open("GET",url);
			xmlHttp.onreadystatechange=function(){
				if(xmlHttp.readyState==4 && xmlHttp.status==200){
					if(xmlHttp.responseText=='1') {
						$("#the_mes"+mes_id).css("display","none");
					}
				}		
			};
			xmlHttp.send(); 
		}

//鼠标移动到哪条私信上，就出现 删除 链接
		function show_del(mes_id) {
			$("#del"+mes_id).css('visibility','visible');
		}
//鼠标移开,删除 链接消失
		function hide_del(mes_id) {
			$("#del"+mes_id).css('visibility','hidden');
		}
	</script>

</body>
</html>